package com.jmb.api.web.controller.db;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jmb.api.common.result.Result;
import com.jmb.api.entity.Db;
import com.jmb.api.vo.Db.DbInfoVO;
import com.jmb.api.vo.Db.DbQueryVO;
import com.jmb.api.web.service.DbService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "数据源中心")
@RestController
@RequestMapping("/web/db")
public class DbController {
    @Autowired
    private DbService dbService;

    // 新增更新数据源中心
    @Operation(summary = "新增更新数据源中心")
    @PostMapping("/saveOrUpdateDb")
    public Result saveOrUpdateDb(@RequestBody @Valid Db db){
        dbService.saveOrUpdateDb(db);
        return Result.ok();

    }
    // 删除数据源中心
    @Operation(summary = "删除数据源中心")
    @PostMapping("/deleteDb")
    public Result deleteDb(Long id){
        dbService.getById(id);
        return Result.ok();
    }
    // 数据源中心列表
    @Operation(summary = "数据源中心列表")
    @GetMapping("/listDb")
    public Result<IPage<DbInfoVO>> listDb(DbQueryVO dbQueryVO){
        IPage<DbInfoVO> page = new Page<>(dbQueryVO.getPageNum(), dbQueryVO.getPageSize());
        IPage<DbInfoVO> list = dbService.ListDb(page, dbQueryVO);
        return Result.ok(list);
    }

    // 数据源中心详情
    @Operation(summary = "数据源中心详情")
    @GetMapping("/getDb")
    public Result<Db> getDb(@RequestParam Long id){
        Db db = dbService.getById(id);
        return Result.ok(db);
    }
    // 数据源中心测试连接
    @Operation(summary = "数据源中心测试连接")
    @GetMapping("/cheDb")
    public Result checkDb(@RequestParam Long id,Integer executeId){
        String msg = dbService.checkDb(id, executeId);
        return Result.ok(msg);
    }
}
